package com.eastfair.matching.controller;

import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.common.api.ChinaumsLogFeign;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.pay.dto.ChinaumsLogDTO;
import com.eastfair.pay.enumeration.TransactionOrderOrderTypeEnum;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 调用银联日志
 * </p>
 *
 * @author linan
 * @date 2023-05-05
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/matchingChinaumsLog")
@Api(value = "MatchingChinaumsLog", tags = "调用银联日志")
@PreAuth(replace = "pay:/queryCategoryList:")
public class MatchingChinaumsLogController{

    @Value("${com.eastfair.projectId}")
    private Long projectId;

    @Resource
    private ChinaumsLogFeign chinaumsLogFeign;

    /**
     * 支付回调
     * @param orderNumber orderNumber
     * @param orderNumber orderNumber
     * @return String
     */
    @PostMapping("/receiveNotify")
    public String receiveNotify(@RequestParam("orderNumber") String orderNumber,@RequestParam("orderType") TransactionOrderOrderTypeEnum orderType){
        ContextUtil.setProjectId(projectId);
        log.info("receiveNotify - 支付回调 orderNumber：{},orderType：{},",orderNumber,orderType);
        ChinaumsLogDTO chinaumsLog = new ChinaumsLogDTO();
        chinaumsLog.setOrderNum(orderNumber);
        chinaumsLog.setOrderType(orderType);
        chinaumsLogFeign.receiveNotify2(chinaumsLog);
        return "SUCCESS";
    }
}
